package codeTop;

public class q153 {
    public int findMin(int[] nums) {
        int n = nums.length;
        int l = 0;
        int r = nums.length-1;
        while (l <= r) {
            int mid = l+(r-l)/2;
            if (nums[(mid+1)%n]>=nums[mid]&&nums[(mid-1+n)%n]>=nums[mid]){
                return nums[mid];
            }else if (nums[mid]<nums[r]){
                r = mid-1;
            }else {
                l = mid+1;
            }
        }
        return -1;
    }
}
